﻿using Cms.Core.Infrastructure.Common;

using Cms.Core.Infrastructure.Ui;
using System.Collections.Generic;
using System.Linq;


namespace Cms.Core.Infrastructure.Extension
{
   public static class PageResultExtensions
    {

        /// <summary>
        /// 返回动态分页数据
        /// </summary>
        /// <param name="result"></param>
        /// <returns></returns>
        public static PageResult ToPageResult(this PageResult<dynamic> result)
        {
           
            return new PageResult(result.Data, result.Total, result.Message, result.Success);
        }

        public static PageResult ToPageResult<T>(this PageResult<T> result)
        {
            var dynamics = result.Data.Cast<dynamic>().ToList();
        
            return new PageResult(dynamics, result.Total, result.Message, result.Success);
        }

        public static PageResult<T> ToPageResult<T>(this PageResult result)
        {

            return new PageResult<T>()
            {


                Data = result.Data as List<T>,
                Message = result.Message,
                Success = result.Success,
                Total = result.Total
            };
        }

        public static PageResult<dynamic> ToPageResult(this PageResult result)
        {

            return new PageResult<dynamic>()
            {


                Data = result.Data,
                Message = result.Message,
                Success = result.Success,
                Total = result.Total
            };
        }
    }
}
